package cn.itcast.wushangxiantu.BaseAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import java.util.List;

import cn.itcast.wushangxiantu.R;

public class ExpandAdapter extends BaseExpandableListAdapter {
    private Context context;
    private List<String[]> list;
    private String[] names = {"武器", "护具", "戒指", "足具", "灵石","高级灵石"};

    public ExpandAdapter(Context context, List<String[]> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getGroupCount() {
        return list.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return list.get(i).length;
    }

    @Override
    public Object getGroup(int i) {
        return list.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return list.get(i)[i1];
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        view = View.inflate(context, R.layout.expand_1, null);
        ViewHolder1 viewHolder1 = new ViewHolder1(view);
        viewHolder1.tvName.setText(names[i]);
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        view = View.inflate(context, R.layout.expand_1_1, null);
        ViewHolder2 viewHolder2 = new ViewHolder2(view);
        viewHolder2.tvName.setText(list.get(i)[i1]);
        if (i<4){
            viewHolder2.tvSydj.setText((i1*10)+"级装备");
            viewHolder2.tvHuafei.setText("花费金币"+(i1*10+1)*10*(i1*10+1));
        }else {
            viewHolder2.tvHuafei.setText("花费金币0");
        }
        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }

    class ViewHolder1 {
        public View rootView;
        public TextView tvName;

        public ViewHolder1(View rootView) {
            this.rootView = rootView;
            this.tvName = (TextView) rootView.findViewById(R.id.tvName);
        }

    }

    class ViewHolder2 {
        public View rootView;
        public TextView tvName;
        public TextView tvSydj;
        public TextView tvHuafei;

        public ViewHolder2(View rootView) {
            this.rootView = rootView;
            this.tvName = (TextView) rootView.findViewById(R.id.tvName);
            this.tvSydj = (TextView) rootView.findViewById(R.id.tvSydj);
            this.tvHuafei = (TextView) rootView.findViewById(R.id.tvHuafei);
        }

    }
}
